import RPi.GPIO as GPIO
import serial
import time
import socket
import threading

#宏定义
speed_duty=100

#引脚分配
GPIO.setmode(GPIO.BOARD)
speed_pin=22

#引脚模式
GPIO.setup(speed_pin,GPIO.OUT)

#引脚初始化
speed=GPIO.PWM(speed_pin,10000)
speed.start(speed_duty)
uart_lidar=serial.Serial(port="/dev/ttyAMA3",baudrate=115200)
uart_gps=serial.Serial(port="/dev/ttyAMA4",baudrate=115200)

#udp发送数据
host_ip = '192.168.1.244'
port1 = 6633
port2 = 6666
addr1 = (host_ip, port1)
addr2 = (host_ip,port2)

client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

def LIDAR():
    data_lidar=None
    while True:
        data_lidar=uart_lidar.read(1)
        client.sendto(data_lidar,addr1)

def GPS():
    data_gps=None
    while True:
        data_gps=uart_gps.read(1)
        client.sendto(data_gps,addr2)
    
t1 = threading.Thread(target=LIDAR)
t1.start()
t2 = threading.Thread(target=GPS)
t2.start()